$(window).ready(function () {
    $('#btnImprimir').on('click', function (e) {
        e.preventDefault();
        $('#container-kardex').html('');
        $('#wait').removeClass('hidden');
        $.get(appBosch.urlKardex + '/' + $('#employees').val(), {}, function (resp) {
            var b = true;
            if (resp.indexOf('Error:') != -1) {
                resp = resp.replace('Error:', '');
                b = false;
            }
            $('#container-kardex').html(resp);
            if (b) {
                activateKardex();
            }
            $('#wait').addClass('hidden');
        });
    });
});

function activateKardex() {
    var datesToTransform = $('td.dateToTransform');

    for (i=0; i < datesToTransform.length; i++) {
        var obj = $(datesToTransform[i]);
        var d = obj.data('date');
        if (d != '') {
            obj.html(kendo.toString(new Date(d.replace(/-/g, "/")), 'd'));
            obj.attr('title', kendo.toString(new Date(d.replace(/-/g, "/")), 'D'));
        }
    }

    var d = $('.print-date');
    d.html(kendo.toString(new Date(d.data('date').replace(/-/g, "/")), 'D'));

    $('.print-button span').on('click', function () {
        window.print();
    });
}